﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="soidukiandmed2_paring", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Soidukiandmed2Paring))]
    public class Soidukiandmed2ParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISoidukiandmed2Paring clazz;
        
        public Soidukiandmed2ParingSerializer(ISoidukiandmed2Paring clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("kood");
            if (clazz.Kood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("id");
            if (clazz.Id!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Id))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "kood")) {
                goto kood;
            }
            else {
                if ((Reader.LocalName == "id")) {
                    goto id;
                }
                else {
                    return;
                }
            }
        kood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>soidukiandmed2_paring>kood");
            }
            clazz.Kood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kood")).Value;
            goto START;
        id:
            if ((Reader.IsElementNil() == false)) {
                clazz.Id = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("id")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
    }
}
